home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swaga_c.zip / COMM.SWG / 0014_Serial Port Stuff.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  4KB  |  103 lines

  1. {
  2. │    Does anyone have a few minutes to help a novice?   I'm new to Pascal
  3. │  and have just added a new dimension to my Programming interests
  4. │  through the purchase of Borland's Pascal With Objects 7.0 and as I
  5. │  struggle through the 3000 odd pages of documentation I find I'm
  6. │  missing some of the basics.   For example, I'm trying to Write a
  7. │  little phone dialer as an exercise in using OOP and am having trouble
  8. │  talking to the modem With the following:
  9. │  Assign(Port,COM1);   ReWrite(Port);    Write(Port,ATDT);
  10. │    This works fine only if I run my dialer Program after having using
  11. │  another comms Program With my modem. if I try to run it cold I  get
  12. │  Error 160: Device Write fault.  There is obviously some initialization
  13. │  I need to do to "WAKEUP" the modem.
  14.  
  15.  
  16. ...Here's some routines to initialize/manipulates the RS-232 port.
  17. }
  18.  
  19.  
  20. Procedure InitCommPort(IniStr      : Byte;
  21.                        CommPort    : Word;
  22.                    Var LineStatus
  23.                        ModemStatus  : Byte);
  24. (****************************************************************************
  25.   Parameters:
  26.  
  27.         InitStr   -   Initialization paramter
  28.  
  29.                       Bits 7654321     Meaning
  30.                            000           110 baud
  31.                            001           150 baud
  32.                            010           300 baud
  33.                            011           600 baud
  34.                            100          1200 baud
  35.                            101          2400 baud
  36.                            110          4800 baud
  37.                            111          9600 baud
  38.                               00        no parity
  39.                               01        odd parity
  40.                               10        no parity
  41.                               11        even parity
  42.                                 0       1 stop bit
  43.                                 1       2 stop bit
  44.                                  10     7-bit data length
  45.                                  11     8-bit data length
  46.  
  47.                       ie: For 1200/N/8/1 use InitStr = 10000011b
  48.  
  49.         CommPort  -   Communication port (0=com1, 1=com2, 2=com3 etc)
  50.  
  51.         LineStatus    Bits 76543210        Meaning
  52.                            1            time-out error
  53.                             1           transfer shift register empty
  54.                              1          transfer holding register empty
  55.                               1         break interrupt detected
  56.                                1        framing error
  57.                                 1       parity error
  58.                                  1      overrun error
  59.                                   1     data ready
  60.  
  61.         ModemStatus   Bits 76543210         Meaning
  62.                            1            receive line signal detect
  63.                             1           ring indicator
  64.                              1          data set ready (DSR)
  65.                               1         clear to send (CTS)
  66.                                1        delta receive line signal detect
  67.                                 1       trailing edge ring detector
  68.                                  1      delta data set ready (DDSR)
  69.                                   1     delta clear to send  (DCTS)
  70.  
  71. *****************************************************************************)
  72.  
  73. Var
  74.   regs : Registers;         (* Uses Dos Unit *)
  75. begin
  76.   regs.AH := $00;
  77.   regs.AL := InitStr;
  78.   regs.DX := CommPort;
  79.   Intr($14, regs);          (* initialize comm port *)
  80.   LineStatus := regs.AH;
  81.   ModemStatus := regs.AL;
  82. end;  (* InitCommPort *)
  83.  
  84.  
  85. Procedure TransmitChar(Ch: Byte;            (* Character to send *)
  86.                        CommPort: Word;      (* comm port to use  *)
  87.                    Var Code: Byte)          (* return code       *)
  88. (****************************************************************************
  89.  
  90.   notE:   BeFore calling this routine, the port must be first initialized
  91.           by InitCommPort.
  92.  
  93. ****************************************************************************)
  94. Var
  95.   regs : Registers;
  96. begin
  97.   regs.AH := $01;
  98.   regs.AL := Ch;
  99.   regs.DX := CommPort;          (* 0=com1, etc    *)
  100.   Intr($14, regs);              (* send Character *)
  101.   Code := regs.AH               (* return code    *)
  102. end;  (* TransmitChar *)
  103.